# 阿里百练文本对话模式
import  logging
from agent.qwen.api.BaiLianApiService import BaiLianApiService

# 服务配置
# api_key = "sk-bbeb8854532e44ac8e1c21246b181964"
# base_url = "https://dashscope.aliyuncs.com/compatible-mode/v1"
# model = "deepseek-v3.1"
# api_type = "openai"
# stream_out = True
# thinking = True
#
#
# multiChat = True
logger = logging.getLogger("BaiLianTextAgent")


class BaiLianTextAgent:
    def __init__(self, api_key="",
                 base_url="",
                 model="deepseek-v3.1",
                 api_type="openai",
                 stream_out=True,
                 thinking=True,
                 multi_chat=True):
        self.api_key = api_key
        self.base_url = base_url
        self.model = model
        self.api_type = api_type
        self.stream_out = stream_out
        self.thinking = thinking
        # 是否多论对话
        self.multi_chat = multi_chat
        # 模型API
        self.apiService = BaiLianApiService(api_key=api_key, base_url=base_url, model=model, api_type=api_type, stream=stream_out, thinking=thinking)


    # 启动文本对话
    async def start_text_chat(self):
        logger.info(f"api type: {self.api_type}, model: {self.model}")
        # 对话信息
        messages = []
        while True:
            question = input('> 请输入你的问题：')
            if question == 'quit':
                break
            # 追加提问
            messages.append({"role": "user", "content": question})
            # 与模型会话
            answer = self.apiService.chat(messages)
            # 多轮对话
            if self.multi_chat:
                messages.append({"role": "assistant", "content": answer})
            else:
                messages = []



